package users;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Describes what a user may do during a session.
 * Other modules should check this before allowing a
 * user to do something.
 * @author Grunk
 *
 */
public class UserPermissions implements Serializable
{
    private static final long serialVersionUID = 1L;
    public static final int MAY_EDIT_PERMISSIONS = 0;
    public static final int MAY_CHAT = 1;
    public static final int MAY_ADD_UNITS = 2;
    public static final int MAY_REMOVE_UNITS = 3;
    public static final int MAY_MOVE_UNITS = 4;
    public static final int MAY_EDIT_UNITS = 5;
    public static final int MAY_EDIT_TERRAIN = 6;
    
    public static final String[] names = {"Edit Permissions", "Chat", "Add Units",
        "Remove Units", "Move Units", "Edit Units", "Edit Terrain"};
    
    private Map<Integer, Permission> list;
    
    public UserPermissions()
    {
        list = new HashMap<Integer, Permission>();
        list.put(MAY_EDIT_PERMISSIONS, new Permission());
        list.put(MAY_CHAT, new Permission());
        list.put(MAY_ADD_UNITS, new Permission());
        list.put(MAY_REMOVE_UNITS, new Permission());
        list.put(MAY_MOVE_UNITS, new Permission());
        list.put(MAY_EDIT_UNITS, new Permission());
        list.put(MAY_EDIT_TERRAIN, new Permission());
    }

    public boolean getPermission(int type)
    {
        return list.get(type).enabled;
    }
    
    public void setPermissions(int type, boolean enabled)
    {
        list.get(type).enabled = enabled;
    }
    
    public void setAllPermissions(boolean enabled)
    {
        list.get(MAY_EDIT_PERMISSIONS).enabled = enabled;
        list.get(MAY_CHAT).enabled = enabled;
        list.get(MAY_ADD_UNITS).enabled = enabled;
        list.get(MAY_REMOVE_UNITS).enabled = enabled;
        list.get(MAY_MOVE_UNITS).enabled = enabled;
        list.get(MAY_EDIT_UNITS).enabled = enabled;
        list.get(MAY_EDIT_TERRAIN).enabled = enabled;
    }
    
    private class Permission implements Serializable
    {
        private static final long serialVersionUID = 1L;
        private boolean enabled;
    }
}
